
var cardInfo =$("#cardIdInfo");
var cardId = $("#cardId");

$(document).ready(function(){
    cardId.blur(validateCardId);

} );

function validateCardId(){
     var val = document.getElementById("cardId").value;
     if(val.length<3 ) {
          cardInfo.addClass('errorField');
          cardInfo.text("ID must be more than 3 munbers") ;
     }else if(val.match(/^\d+(?:\.\d+)?$/)){
            cardInfo.removeClass('errorField');
            cardInfo.text("" ) ;
            return true;
            }else{
            cardInfo.addClass('errorField');
            cardInfo.text("Invalid Card ID: "+ val) ;
            return false;
         }
}
function load(){
    if(validateCardId()){
        var params =  "cardId="+document.getElementById("cardId").value;
        ajaxPost("?tld/getCardInfoForDose", params, function(data) {
                   var response =JSON.parse(data);
                   if (response.status==false) {
                       return;
                   }
                    $("#cardInfo").html("" ) ;
                    $("#cardInfo").html(response.tableHtml) ;
                    $("#messagePanel").removeClass();
                    $("#messagePanel").html("" ) ;

               });

    }
}
 function validateDoseValue(){
     var val= document.getElementById("doseValue").value;
     if(val.match(/^\d+(?:\.\d+)?$/)){
         $("#doseValueInfo").removeClass('errorField');
                $("#doseValueInfo").text("" ) ;
			    return true;
             }else{

                  $("#doseValueInfo").addClass('errorField');
                 $("#doseValueInfo").text("Invalid Dose Value: "+val ) ;
			    return false;
     }


 }
function addDoseValue(){
    if(validateDoseValue()){
       var params =  "id="+document.getElementById("id").value+"&" +"card="+document.getElementById("card").value+"&" + encodeURIComponent("doseValue") + "="+$("#doseValue").val();
        ajaxPost("?dis/updateDoseManually", params, function(data) {
                   var response =JSON.parse(data);
                   if (response.status==false) {
                       return;
                   }
                    $("#messagePanel").removeClass();
                    $("#messagePanel").addClass(response.type);
                    $("#messagePanel").html(response.message ) ;
               });

    }
}



